﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Database.Model.Customers>" %>



<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>


<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdPriceContidions";
                                        settings.KeyFieldName = "IdPriceCondition";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Contracts", Action = "CustomerPriceConditionsPartialEdit", customerId = Model.IdCustomer };
                                        settings.SettingsPager.PageSize = 20;

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.LegalEntityName;
                                            column.FieldName = "IdLegalEntity";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {

                                                comboBoxProperties.DataSource = Model.LegalEntities;
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdLegalEntity";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        
                                        settings.Columns.Add(column =>
                                                                 {
                                                                     column.Caption = Resourses.Product;
                                                                     column.FieldName = "IdProduct";
                                                                     
                                                                     column.SetEditItemTemplateContent(c=>
                                                                                                           {

                                                                                                             // PriceConditions value = c.Grid.GetRowValues(c.VisibleIndex, c.Column.FieldName) as PriceConditions;
                                                                                                               //if (value == null)
                                                                                                               //    value = DB.Products.FirstOrDefault();
                                                                                                               var value=DB.Products.FirstOrDefault();
                                                                                                               Html.RenderPartial("ProductSelector", value);
                                                                                                           });
                                                                    
                                                                 });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.PriceEuroM;
                                            column.FieldName = "Price";
                                          
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.StartDate;
                                            column.FieldName = "DateStart";
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.EndDate;
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                            column.FieldName = "DateEnd";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.PriceConditionType;
                                            column.FieldName = "IdPriceConditionType";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new PriceConditionTypesCollection();
                                                comboBoxProperties.DataSource = col.PriceConditionTypesList;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdPriceConditionType";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.AdditionalContract;
                                            column.FieldName = "IdContract";
                                        });


                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TransportCondition;
                                            column.FieldName = "IdTransportCondition";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = Model.TransportConditions;
                                                comboBoxProperties.DataSource = col;
                                                comboBoxProperties.TextField = "TransportConditionStr";
                                                comboBoxProperties.ValueField = "IdTransportCondition";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.MetresInPallette;
                                            column.FieldName = "MetresInPalletteStr";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ExtraCharge;
                                            column.FieldName = "ExtraChargeStr";
                                        });
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.PriceWithTransport;
                                            column.FieldName = "PriceWithTransportStr";
                                        });


                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Contracts", Action = "CustomerPriceConditionsPartialUpdate", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Contracts", Action = "CustomerPriceConditionsPartialAdd", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Contracts", Action = "CustomerPriceConditionsPartialDelete", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;

                                     
                                    }).Bind(Model.PriceConditions).GetHtml();
                                    
                                    
                                    %>

